@@ -5,7 +5,6 @@ from django.contrib.admin.views.decorators import staff_member_required  | 
            ||
| 5 | 5 | 
                from django.db import transaction  | 
            
| 6 | 6 | 
                from django_logit import logit  | 
            
| 7 | 7 | 
                from django_response import response  | 
            
| 8 | 
                -from TimeConvert import TimeConvert as tc  | 
            |
| 9 | 8 | 
                 | 
            
| 10 | 9 | 
                from integral.models import SaleclerkIntegralIncomeExpensesInfo, SaleclerkSubmitLogInfo  | 
            
| 11 | 10 | 
                from mch.models import BrandInfo, DistributorInfo, ModelInfo, SaleclerkInfo  | 
            
                @@ -43,7 +42,7 @@ def exec_del_clerk_sale_submit(pk, username):  | 
            ||
| 43 | 42 | 
                 | 
            
| 44 | 43 | 
                try:  | 
            
| 45 | 44 | 
                model = ModelInfo.objects.get(pk=ssli.model_pk)  | 
            
| 46 | 
                - except SaleclerkInfo.DoesNotExist:  | 
            |
| 45 | 
                + except ModelInfo.DoesNotExist:  | 
            |
| 47 | 46 | 
                return response()  | 
            
| 48 | 47 | 
                 | 
            
| 49 | 48 | 
                try:  | 
            
                @@ -63,7 +62,6 @@ def exec_del_clerk_sale_submit(pk, username):  | 
            ||
| 63 | 62 | 
                clerk.total_integral -= integral  | 
            
| 64 | 63 | 
                clerk.save()  | 
            
| 65 | 64 | 
                 | 
            
| 66 | 
                - # ymd = tc.local_string(format='%Y%m%d')  | 
            |
| 67 | 65 | 
                ymd = str(ssli.ymd)  | 
            
| 68 | 66 | 
                 | 
            
| 69 | 67 | 
                if not clerk.test_user and not ssli.dupload:  | 
            
                @@ -7,11 +7,14 @@ from django.conf import settings  | 
            ||
| 7 | 7 | 
                from pysnippets.strsnippets import strip  | 
            
| 8 | 8 | 
                from TimeConvert import TimeConvert as tc  | 
            
| 9 | 9 | 
                 | 
            
| 10 | 
                -from mch.models import BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, ModelCameraBodyInfo, ModelInfo  | 
            |
| 10 | 
                +from integral.models import SaleclerkSubmitLogInfo  | 
            |
| 11 | 
                +from mch.models import BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, ModelCameraBodyInfo, ModelInfo, SaleclerkInfo  | 
            |
| 11 | 12 | 
                from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo,  | 
            
| 12 | 13 | 
                ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo,  | 
            
| 13 | 14 | 
                DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo,  | 
            
| 14 | 15 | 
                SaleStatisticInfo)  | 
            
| 16 | 
                +from statistic.models import (DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo,  | 
            |
| 17 | 
                + SaleclerkSaleStatisticInfo, SaleStatisticInfo)  | 
            |
| 15 | 18 | 
                from utils.redis.connect import r  | 
            
| 16 | 19 | 
                from utils.redis.rkeys import MINI_PROGRAM_GIS_LIST  | 
            
| 17 | 20 | 
                 | 
            
                @@ -327,3 +330,170 @@ def refreshs():  | 
            ||
| 327 | 330 | 
                'phone': log.phone,  | 
            
| 328 | 331 | 
                'ymd': tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d'),  | 
            
| 329 | 332 | 
                })  | 
            
| 333 | 
                +  | 
            |
| 334 | 
                +  | 
            |
| 335 | 
                +def refreshs2():  | 
            |
| 336 | 
                + SaleStatisticInfo.objects.all().delete()  | 
            |
| 337 | 
                + ModelSaleStatisticInfo.objects.all().delete()  | 
            |
| 338 | 
                + DistributorSaleStatisticInfo.objects.all().delete()  | 
            |
| 339 | 
                + ProvinceSaleStatisticInfo.objects.all().delete()  | 
            |
| 340 | 
                + SaleclerkSaleStatisticInfo.objects.all().delete()  | 
            |
| 341 | 
                +  | 
            |
| 342 | 
                + logs = SaleclerkSubmitLogInfo.objects.filter(status=True)  | 
            |
| 343 | 
                +  | 
            |
| 344 | 
                + for log in logs:  | 
            |
| 345 | 
                + ymd = tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d')  | 
            |
| 346 | 
                +  | 
            |
| 347 | 
                + try:  | 
            |
| 348 | 
                + brand = BrandInfo.objects.get(pk=log.brand_pk)  | 
            |
| 349 | 
                + except BrandInfo.DoesNotExist:  | 
            |
| 350 | 
                + continue  | 
            |
| 351 | 
                +  | 
            |
| 352 | 
                + try:  | 
            |
| 353 | 
                + model = ModelInfo.objects.get(pk=log.model_pk)  | 
            |
| 354 | 
                + except ModelInfo.DoesNotExist:  | 
            |
| 355 | 
                + continue  | 
            |
| 356 | 
                +  | 
            |
| 357 | 
                + try:  | 
            |
| 358 | 
                + clerk = SaleclerkInfo.objects.select_for_update().get(clerk_id=log.clerk_id, status=True)  | 
            |
| 359 | 
                + except SaleclerkInfo.DoesNotExist:  | 
            |
| 360 | 
                + continue  | 
            |
| 361 | 
                +  | 
            |
| 362 | 
                + try:  | 
            |
| 363 | 
                + distributor = DistributorInfo.objects.get(distributor_id=clerk.distributor_id)  | 
            |
| 364 | 
                + except DistributorInfo.DoesNotExist:  | 
            |
| 365 | 
                + continue  | 
            |
| 366 | 
                +  | 
            |
| 367 | 
                + # 日销量统计  | 
            |
| 368 | 
                + ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 369 | 
                + brand_id=brand.brand_id,  | 
            |
| 370 | 
                + ymd=ymd,  | 
            |
| 371 | 
                + )  | 
            |
| 372 | 
                + ssi.num += 1  | 
            |
| 373 | 
                + ssi.save()  | 
            |
| 374 | 
                + # 月销量统计  | 
            |
| 375 | 
                + ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 376 | 
                + brand_id=brand.brand_id,  | 
            |
| 377 | 
                + ymd=ymd[:6],  | 
            |
| 378 | 
                + )  | 
            |
| 379 | 
                + ssi.num += 1  | 
            |
| 380 | 
                + ssi.save()  | 
            |
| 381 | 
                + # 年销量统计  | 
            |
| 382 | 
                + ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 383 | 
                + brand_id=brand.brand_id,  | 
            |
| 384 | 
                + ymd=ymd[:4],  | 
            |
| 385 | 
                + )  | 
            |
| 386 | 
                + ssi.num += 1  | 
            |
| 387 | 
                + ssi.save()  | 
            |
| 388 | 
                +  | 
            |
| 389 | 
                + # 型号销量统计  | 
            |
| 390 | 
                + mssi, _ = ModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 391 | 
                + brand_id=brand.brand_id,  | 
            |
| 392 | 
                + model_name=model.model_uni_name,  | 
            |
| 393 | 
                + ymd=ymd,  | 
            |
| 394 | 
                + )  | 
            |
| 395 | 
                + mssi.saleclerks += [clerk.clerk_id]  | 
            |
| 396 | 
                + mssi.num = len(mssi.saleclerks)  | 
            |
| 397 | 
                + mssi.save()  | 
            |
| 398 | 
                +  | 
            |
| 399 | 
                + mssi, _ = ModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 400 | 
                + brand_id=brand.brand_id,  | 
            |
| 401 | 
                + model_name=model.model_uni_name,  | 
            |
| 402 | 
                + ymd=ymd[:6],  | 
            |
| 403 | 
                + )  | 
            |
| 404 | 
                + mssi.saleclerks += [clerk.clerk_id]  | 
            |
| 405 | 
                + mssi.num = len(mssi.saleclerks)  | 
            |
| 406 | 
                + mssi.save()  | 
            |
| 407 | 
                +  | 
            |
| 408 | 
                + mssi, _ = ModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 409 | 
                + brand_id=brand.brand_id,  | 
            |
| 410 | 
                + model_name=model.model_uni_name,  | 
            |
| 411 | 
                + ymd=ymd[:4],  | 
            |
| 412 | 
                + )  | 
            |
| 413 | 
                + mssi.saleclerks += [clerk.clerk_id]  | 
            |
| 414 | 
                + mssi.num = len(mssi.saleclerks)  | 
            |
| 415 | 
                + mssi.save()  | 
            |
| 416 | 
                +  | 
            |
| 417 | 
                + # 经销商销量统计  | 
            |
| 418 | 
                + dssi, _ = DistributorSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 419 | 
                + brand_id=brand.brand_id,  | 
            |
| 420 | 
                + distributor_id=distributor.distributor_id,  | 
            |
| 421 | 
                + ymd=ymd,  | 
            |
| 422 | 
                + )  | 
            |
| 423 | 
                + dssi.distributor_name = distributor.distributor_name  | 
            |
| 424 | 
                + dssi.num += 1  | 
            |
| 425 | 
                + dssi.save()  | 
            |
| 426 | 
                +  | 
            |
| 427 | 
                + dssi2, _ = DistributorSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 428 | 
                + brand_id=brand.brand_id,  | 
            |
| 429 | 
                + distributor_id=distributor.distributor_id,  | 
            |
| 430 | 
                + ymd=0,  | 
            |
| 431 | 
                + )  | 
            |
| 432 | 
                + dssi2.distributor_name = distributor.distributor_name  | 
            |
| 433 | 
                + dssi2.num += 1  | 
            |
| 434 | 
                + dssi2.save()  | 
            |
| 435 | 
                +  | 
            |
| 436 | 
                + # 日省份销量统计  | 
            |
| 437 | 
                + pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 438 | 
                + brand_id=brand.brand_id,  | 
            |
| 439 | 
                + province_code=distributor.distributor_province_code,  | 
            |
| 440 | 
                + ymd=ymd,  | 
            |
| 441 | 
                + )  | 
            |
| 442 | 
                + pssi.province_name = distributor.distributor_province_name  | 
            |
| 443 | 
                + pssi.num += 1  | 
            |
| 444 | 
                + pssi.save()  | 
            |
| 445 | 
                + # 月省份销量统计  | 
            |
| 446 | 
                + pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 447 | 
                + brand_id=brand.brand_id,  | 
            |
| 448 | 
                + province_code=distributor.distributor_province_code,  | 
            |
| 449 | 
                + ymd=ymd[:6],  | 
            |
| 450 | 
                + )  | 
            |
| 451 | 
                + pssi.province_name = distributor.distributor_province_name  | 
            |
| 452 | 
                + pssi.num += 1  | 
            |
| 453 | 
                + pssi.save()  | 
            |
| 454 | 
                + # 年省份销量统计  | 
            |
| 455 | 
                + pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 456 | 
                + brand_id=brand.brand_id,  | 
            |
| 457 | 
                + province_code=distributor.distributor_province_code,  | 
            |
| 458 | 
                + ymd=ymd[:4],  | 
            |
| 459 | 
                + )  | 
            |
| 460 | 
                + pssi.province_name = distributor.distributor_province_name  | 
            |
| 461 | 
                + pssi.num += 1  | 
            |
| 462 | 
                + pssi.save()  | 
            |
| 463 | 
                +  | 
            |
| 464 | 
                + # 日销售员销量统计  | 
            |
| 465 | 
                + sssi, _ = SaleclerkSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 466 | 
                + brand_id=brand.brand_id,  | 
            |
| 467 | 
                + clerk_id=clerk.clerk_id,  | 
            |
| 468 | 
                + ymd=ymd,  | 
            |
| 469 | 
                + )  | 
            |
| 470 | 
                + sssi.distributor_id = distributor.distributor_id  | 
            |
| 471 | 
                + sssi.distributor_name = distributor.distributor_name  | 
            |
| 472 | 
                + sssi.distributor_short_name = distributor.distributor_short_name  | 
            |
| 473 | 
                + sssi.clerk_name = clerk.clerk_name  | 
            |
| 474 | 
                + sssi.num += 1  | 
            |
| 475 | 
                + sssi.save()  | 
            |
| 476 | 
                + # 月销售员销量统计  | 
            |
| 477 | 
                + sssi, _ = SaleclerkSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 478 | 
                + brand_id=brand.brand_id,  | 
            |
| 479 | 
                + clerk_id=clerk.clerk_id,  | 
            |
| 480 | 
                + ymd=ymd[:6],  | 
            |
| 481 | 
                + )  | 
            |
| 482 | 
                + sssi.distributor_id = distributor.distributor_id  | 
            |
| 483 | 
                + sssi.distributor_name = distributor.distributor_name  | 
            |
| 484 | 
                + sssi.distributor_short_name = distributor.distributor_short_name  | 
            |
| 485 | 
                + sssi.clerk_name = clerk.clerk_name  | 
            |
| 486 | 
                + sssi.num += 1  | 
            |
| 487 | 
                + sssi.save()  | 
            |
| 488 | 
                + # 年销售员销量统计  | 
            |
| 489 | 
                + sssi, _ = SaleclerkSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 490 | 
                + brand_id=brand.brand_id,  | 
            |
| 491 | 
                + clerk_id=clerk.clerk_id,  | 
            |
| 492 | 
                + ymd=ymd[:4],  | 
            |
| 493 | 
                + )  | 
            |
| 494 | 
                + sssi.distributor_id = distributor.distributor_id  | 
            |
| 495 | 
                + sssi.distributor_name = distributor.distributor_name  | 
            |
| 496 | 
                + sssi.distributor_short_name = distributor.distributor_short_name  | 
            |
| 497 | 
                + sssi.clerk_name = clerk.clerk_name  | 
            |
| 498 | 
                + sssi.num += 1  | 
            |
| 499 | 
                + sssi.save()  |